package com.hiabr.iep.common.web.config;

import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description JacksonConfig
 */
@Configuration
public class JacksonConfig {

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        Jackson2ObjectMapperBuilderCustomizer cunstomizer = jacksonObjectMapperBuilder -> {
            //解决由于Long属性字段过长，前端js精度丢失问题
            //页面中需要数值类型进行计算的数据也转换成了String类型，导致计算失败，如分页等
            //将大于9000000000000000L的数值转成String，9000000000000000L以下的数据继续使用Long型
            jacksonObjectMapperBuilder.serializerByType(Long.TYPE, WebLongSerializer.instance);
            jacksonObjectMapperBuilder.serializerByType(Long.class, WebLongSerializer.instance);
        };
        return cunstomizer;
    }
}
